<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMapAsync"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center  :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailForm" :model="detailForm" label-width="120px">
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>基本信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="交易流水号" prop="id">
                <el-input v-model="detailForm.id" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="报文标识号" prop="pkgid">
                <el-input v-model="detailForm.pkgid" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="内部机构号" prop="brno">
                <el-select style="width: 100%" v-model="detailForm.brno" placeholder="内部机构号" :disabled="true">
                  <el-option
                    v-for="dict in dictMap['Cnaps2Dict.CP2_BRNO']"
                    :key="dict.value"
                    :label="`${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="来往标志" prop="drct">
                <el-select style="width: 100%" v-model="detailForm.drct" placeholder="来往标志" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.DRCTCODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.workdate"
                  value-format="yyyyMMdd"
                  type="date"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="CPG日期" prop="vdate">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.vdate"
                  value-format="yyyyMMdd"
                  type="date"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="交易渠道" prop="source">
                <el-select style="width: 100%" v-model="detailForm.source" placeholder="柜面交易" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.TXN_SOURCE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统编号" prop="sysCode">
                <el-select style="width: 100%" v-model="detailForm.sysCode" placeholder="系统编号" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.SYS_CODE_310_312"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="发起方" prop="sender">
                <el-input v-model="detailForm.sender" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发起方名称" prop="senderName">
                <el-input v-model="detailForm.senderName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="接收方" prop="rcver">
                <el-input v-model="detailForm.rcver" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="接收方名称" prop="rcverName">
                <el-input v-model="detailForm.rcverName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="信息内容" prop="content">
                <el-input type="textarea" v-model="detailForm.content" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="备注" prop="remarks">
                <el-input type="textarea" v-model="detailForm.remarks" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>处理信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="中心状态" prop="procStatus">
                <el-select style="width: 100%" v-model="detailForm.procStatus" placeholder="中心状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="通讯状态" prop="status">
                <el-select style="width: 100%" v-model="detailForm.status" placeholder="通讯状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.PKG_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="录入操作员" prop="mdTlrno">
                <el-input v-model="detailForm.mdTlrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="录入时间" prop="mdTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.mdTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="报文发送时间" prop="sndTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.sndTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文接收时间" prop="rcvTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.rcvTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="通用报文处理码" prop="procCode">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.procCode === null || detailForm.procCode === undefined
                      ? ''
                      : detailForm.procCode + '-' + detailForm.procCodeDesc
                  "
                  placeholder="原业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="业务拒绝信息" prop="rejectInfo">
                <el-input type="textarea" v-model="detailForm.rejectInfo" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="审核附言" prop="audRemarks">
                <el-input type="textarea" v-model="detailForm.audRemarks" maxlength="128" show-word-limit/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="approve" v-loading.fullscreen.lock="loading">审 核</el-button>
        <el-button type="primary" @click="reject" v-loading.fullscreen.lock="loading">拒 绝</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigApprove,
  findFreeApproveApprvoe,
  findFreeApproveDeatil,
  findFreeApproveReject,
} from "@/api/cnaps/ccms/303";
import { listPageMixin } from "@/libs/listPageMixin";
import { mapGetters } from "vuex";
export default {
  name: "FreeFormatApprove",
  mixins: [listPageMixin],
  components: {},
  computed: {
    ...mapGetters(["name", "globalBusData"]),
  },
  created() {
    this.$set(this.queryParams, "brno", this.globalBusData.brno);
  },
  watch: {
    globalBusData: {
      handler(val) {
        this.$set(this.queryParams, "brno", val.brno);
      },
      deep: true,
      immediate: true,
    },
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        idSeqno: undefined,
        conDrct: undefined,
        sysCode: undefined,
        startvdate: undefined,
        endvdate: undefined,
        startworkdate: undefined,
        endworkdate: undefined,
        conSender: undefined,
        conRcver: undefined,
        brno: undefined,
      },
      loading: false,
      // 搜索
      formOptions: [],
      searchFormDictList: [
        "DRCTCODE",
        "SYS_CODE_310_312",
        "PROCESSSTATUS",
        "TXN_SOURCE",
        "PKG_STATUS",
        "Cnaps2Dict.CP2_BRNO",
      ],
      // 列信息
      regConfig: apiUrlConfigApprove,
      tableBindColumns: [
        { prop: "brno", label: "内部机构号", dictCode: "Cnaps2Dict.CP2_BRNO" },
        { prop: "id", label: "交易流水号" },
        { prop: "sysCode", label: "系统编号", dictCode: "SYS_CODE_310_312" },
        { prop: "drct", label: "来往账标志", dictCode: "DRCTCODE" },
        { prop: "vdate", label: "CPG日期", type: "date" },
        { prop: "workdate", label: "工作日期", type: "date" },
        { prop: "sender", label: "发起方" },
        { prop: "rcver", label: "接收方" },
        { prop: "procStatus", label: "中心状态", dictCode: "PROCESSSTATUS" },
      ],
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {
        id: undefined,
        pkgId: undefined,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {},
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索
      {
        type: "input",
        prop: "idSeqno",
        defaultAttr: {
          size: "small",
          label: "流水号",
          placeholder: "请输入流水号",
        },
      },
      {
        type: "search-dept-tree",
        prop: "brno",
        defaultAttr: {
          radio: false,
          linkParentChoose: false,
          label: "分行选择",
          placeholder: "请选择分行",
        },
      },
      {
        type: "dict",
        dict: "DRCTCODE",
        prop: "conDrct",
        defaultAttr: {
          size: "small",
          label: "来往标志",
          placeholder: "请输入来往标志",
        },
      },
      {
        type: "dict",
        dict: "SYS_CODE_310_312",
        prop: "sysCode",
        defaultAttr: {
          size: "small",
          label: "系统编号",
          placeholder: "请选择系统编号",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "startvdate",
          endTimeName: "endvdate",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG开始日期", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "startworkdate",
          endTimeName: "endworkdate",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "input",
        prop: "conSender",
        defaultAttr: {
          size: "small",
          label: "发起方",
          placeholder: "请输入发起方",
        },
      },

      {
        type: "input",
        prop: "conRcver",
        defaultAttr: {
          size: "small",
          label: "接收方",
          placeholder: "请输入接收方",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "自由格式审核明细";
      findFreeApproveDeatil(row.id).then((response) => {
        console.log(response.result);
        this.detailForm = response.result;
        this.open = true;
      });
    },
    //点击审核按钮
    approve: function () {
      this.loading = false;
      findFreeApproveApprvoe(this.detailForm)
        .then((response) => {
          this.msgSuccess("审核成功");
          this.open = false;
          this.loading = false;
          this.$nextTick(() => {
            this.$refs.dataTable.doQuery(true);
          });
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    //点击拒绝按钮
    reject() {
      this.loading = true;
      findFreeApproveReject(this.detailForm)
        .then((response) => {
          this.msgSuccess("拒绝成功");
          this.open = false;
          this.loading = false;
          this.$nextTick(() => {
            this.$refs.dataTable.doQuery(true);
          });
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
